package com.open.capacity.talented.controller;

import com.open.capacity.common.web.Result;
import com.open.capacity.talented.dto.IndustryEditDto;
import com.open.capacity.talented.dto.LayuiDto;
import com.open.capacity.talented.dto.QueryByIndustryIdsDto;
import com.open.capacity.talented.service.IndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/talented")
public class TalentedController {
    @Autowired
    IndustryService industryService;

    //查询所有人才及所属行业，职业
    @GetMapping("/list")
    public Result list(LayuiDto dto,Integer enabled){
        return Result.succeed(industryService.queryTalentedWithIndustryByPageAndLimit(dto,enabled),"ok");
    }

    //根据人才id，查询所有人才及所属行业，职业
    @PostMapping("/IndustryIdsByUserId")
    public Result user(@RequestBody Long id){
        return Result.succeed(industryService.queryIndustryIdsByUserId(id),"ok");
    }
    //根据父级id，分别查询所有行业，职业
    @PostMapping("/industryByParentId")
    public Result listIndustry(@RequestBody Long parentId){
        return Result.succeed(industryService.queryIndustryByParentId(parentId),"ok");
    }

    //根据父级id，分别查询所有行业，职业
    @PostMapping("/industryByIds")
    public Result listIndustry(@RequestBody List<Long> ids){
        if(ids.size() == 0){
            return Result.succeed(null,"ok");
        }
        return Result.succeed(industryService.queryIndustryListByIds(ids),"ok");
    }

    //查询所有行业及职业
    @PostMapping("/industryListAll")
    public Result listAll(){
        return Result.succeed(industryService.queryAllIndustryList(),"ok");
    }
    //根据行业id，查询所有相关人才
    @PostMapping("/listByIndustryIds")
    public Result listByIndustry(@RequestBody QueryByIndustryIdsDto dto){
        return Result.succeed(industryService.queryTalentedByIndustryIds(dto),"ok");
    }

    //编辑指定用户所属行业
    @PostMapping("/editByUserId")
    public Result editByUserId(@RequestBody IndustryEditDto dto){
        boolean flag = industryService.changeTalentedIndustryByUserId(dto);
        if(flag){
            return Result.succeed("ok");
        }
        return Result.failed("failed");
    }

}
